//
//  AppDelegate.m
//  UI01_作业
//
//  Created by dllo on 15/7/20.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
//    [self myview1];
    self.arr2 = [NSMutableArray arrayWithObjects:@"影视", @"图书",@"汽车", @"娱乐",@"时尚", @"科技", @"综艺", @"游戏", @"音乐", @"论坛", nil];
    self.arr1 = [NSMutableArray array];
    [self myview2];
    NSLog(@"时尚");
    [self.window release];
    return YES;
}
- (void)myview1
{
    for (int i = 0; i < 20; i++) {
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(i / 5 * 60 + 10, i % 5 * 60 + 10, 50, 50)];
        view.backgroundColor = [UIColor redColor];
        [self.window addSubview:view];
        [view release];
    }
}
- (void)myview2
{

    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.window.frame.size.width, 60)];
    view.backgroundColor = [UIColor greenColor];
    [self.window addSubview:view];
    [view release];
    
    UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(150, 15, 60, 30)];
    label2.text = @"網易";
    label2.font = [UIFont systemFontOfSize:25];
    label2.textColor = [UIColor redColor];
    [self.window addSubview:label2];
    [label2 release];
    
    UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(0, 250, self.window.frame.size.width, 40)];
    view1.backgroundColor = [UIColor blueColor];
    [self.window addSubview:view1];
    [view1 release];
    
    self.view1 = [[UIView alloc] initWithFrame:CGRectMake(0, 60, self.window.frame.size.width, 190)];
    self.view1.backgroundColor = [UIColor whiteColor];
    [self.window addSubview:self.view1];
    [self.view1 release];
    
    self.view2 = [[UIView alloc] initWithFrame:CGRectMake(0, 290, self.window.frame.size.width, self.window.frame.size.height - 290)];
    self.view2.backgroundColor = [UIColor whiteColor];
    [self.window addSubview: self.view2];
    [self.view2 release];
    
    
    for (int i = 0; i < self.arr1.count; i++) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
        button.frame = CGRectMake(i / 2 * 60 + 20, i % 2 * 60 +30, 50, 50);
        [self.view1 addSubview:button];
        [button setTitle:[self.arr1 objectAtIndex:i] forState:UIControlStateNormal];
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        button.tag = (i + 1) * 10;
        [button addTarget:self action:@selector(click1:) forControlEvents:UIControlEventTouchUpInside];
    }

    
    for (int i = 0; i < self.arr2.count; i++) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
        button.frame = CGRectMake(i / 2 * 60 + 20, i % 2 * 60 +30, 50, 50);
        [self.view2 addSubview:button];
        [button setTitle:[self.arr2 objectAtIndex:i] forState:UIControlStateNormal];
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        button.tag = i + 1;
        [button addTarget:self action:@selector(click2:) forControlEvents:UIControlEventTouchUpInside];
    }
    
    
    
}

- (void)click1:(UIButton *)button
{
    NSString *string = self.arr1[button.tag  / 10 - 1];
    [self.arr1 removeObjectAtIndex:button.tag / 10 - 1];
    [self.arr2 addObject:string];
    [self.view1 removeFromSuperview];
    [self.view2 removeFromSuperview];
    [self myview2];
}
- (void)click2:(UIButton *)button
{
    NSString *string = self.arr2[button.tag - 1];
    [self.arr2 removeObjectAtIndex:button.tag  - 1];
    [self.arr1 addObject:string];
    [self.view1 removeFromSuperview];
    [self.view2 removeFromSuperview];
    [self myview2];
}
- (void)dealloc
{
    [_arr1 release];
    [_arr2 release];
    [_view1 release];
    [_view2 release];
    [_window release];
    [super dealloc];
}






- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
